home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / sos6663d / mini3d.asm < prev    next >
Assembly Source File  |  1996-05-08  |  16KB  |  360 lines

  1. ; Hi guys...       
  2. ; Here it is...    
  3. ; The long awaited source code for my 666 byte wireframe-vector engine ...
  4. ; i have released it by request of some guys...
  5. ;                  
  6. ; Sum facts...     
  7. ; You have to run a postprocessor to make it excactly 666 byte
  8. ; i have included one, see POSTPROC.PAS for further information
  9. ; (For the beginners: The postprocessor cuts the uninitialised data
  10. ; from the back of the COM (that data after the ZERODATA_START label)
  11. ; a little routine called at the beginning of the program sets this area
  12. ; to zero, and SHAZAM we have gained in this case 708 bytes :))
  13. ;                  
  14. ; if you want to know more about keeping your code small read Imphobia #8
  15. ; there's a very interesting article by THE FAKER ...
  16. ;                  
  17. ; Sum words about the rotation: Yes, it's rotated only around one angle but
  18. ; in 3 Dimensions, i had to rotate it around a single angle to gain size...
  19. ;                  
  20. ; The first quarter of the sine table is precalclated, the other quarters
  21. ; and the cosines can be derived from them...
  22. ;                  
  23. ; Well i think you should know know everything about it..
  24. ; Go on, make it smaller and send your work to me (you can find my contact
  25. ; adresses farther down)...
  26. ; The first one who'll get it below 400 byte will get a bottle of 
  27. ; luxembourgish beer ;-)
  28. ;                  
  29. ; Greets fly out to (no speacial order): The rest of SoS, Poll Fabaire,
  30. ;  Lone Wolf/iGH, The Cha()T, Fire, Magic/Finix, Slaine, Mikee Mouse, 
  31. ;  Krash/AcmE, Speed Freak, Kaos, X-Treme, 4e2CS from LCD, Crusty, Deadline,
  32. ;  LastV8/CSi, Kraut, Phos4, Tasmaniac, Screamager, Dwarf, Stingray, Tonic,
  33. ;  and all those i forgot...
  34. ;                  
  35. ; How to contact me ...
  36. ; ~~~~~~~~~~~~~~~~~
  37. ; BBS: Neurotic +352-313377 (Mail to BLACK AXE)
  38. ;      Coders Corner +352-313377 (Mail to BLACK AXE)
  39. ;                  
  40. ; Snail-Mail:     Laurent Schmalen
  41. ;                 6, rue Tony Schmit
  42. ;                 L-9081 Ettelbruck
  43. ;                 Luxembourg
  44. ;                  
  45. ; Voice-Phone: +352-810013  (from 18:00 to 21:30)
  46. ;                  
  47. ; HAVE FUN!        
  48. ;            BLACK AXE / SoS, 12th May 1996
  49.                                            
  50.                                            
  51. .386p              
  52. wirecol   equ 14          ; Color of the Object 
  53. maxpnts   equ 8           ; Number of points (from 1 to MAXPNTS)
  54. maxplanes equ 6           ; Number of Planes (from 1 to MAXPLANES)
  55. xpos      equ 160         ; X-Position of the Object
  56. ypos      equ 140         ; Y-Position of the Object
  57. depth     equ 1524        ; X-Position of the Object (ZooM)
  58.                           
  59. code    segment use16 'CODE'
  60.         org     100h      
  61.         assume cs:code,ds:code
  62.                           
  63. start:  jmp     ufankk    
  64.                           
  65. db      'SOS RULEZ !!   '                ; PlaceHolder to make it 666 byte :)
  66.                                      ; So, it's only 651 bytes big 
  67. angleun union                     
  68.         b db ?                  
  69.         w dw ?                  
  70. angleun ends                    
  71.                                 
  72. ptsxyz  dw -200,-200, 200        ; The base object (a nice cube :))
  73.         dw  200,-200, 200                                          
  74.         dw  200, 200, 200                                          
  75.         dw -200, 200, 200                                          
  76.         dw -200,-200,-200                                          
  77.         dw  200,-200,-200                                          
  78.         dw -200, 200,-200                                          
  79.         dw  200, 200,-200                                          
  80.                                                                    
  81. planes  db 0,1,2,3              ; Everyone should know it :)
  82.         db 4,5,7,6                                          
  83.         db 0,4,6,3                                                 
  84.         db 1,5,7,2                                                 
  85.         db 0,4,5,1                                          
  86.         db 6,7,2,3                                          
  87.                                                             
  88. kk      struc                                                           
  89.         x dw ?                                              
  90.         y dw ?                                              
  91.         z dw ?                                              
  92. ends                                                        
  93.                                                             
  94. damn    proc    near                ; Does that (for the rotate proc)                        
  95.         imul    bx                  ; To gain sum silly bytes    
  96.         shl     edx,16                                        
  97.         mov     dx,ax                                         
  98.         mov     edi,edx                                       
  99.         ret                                                   
  100. damn    endp                                                  
  101.                                                               
  102. rotate  proc    near                                         
  103. ;iNPUT   BX    CX
  104. ; DESTROYS:  QUITE A LOT
  105.         mov     si,angle.w                                    
  106.         add     si,si                                         
  107.         mov     ax,[cosinus+si]                               
  108.         call    damn                                          
  109.                                                               
  110.         mov     ax,[sinus+si]                                 
  111.         imul    cx                                            
  112.         shl     edx,16                                        
  113.         mov     dx,ax                                         
  114.         sub     edi,edx                                       
  115.         sar     edi,8                                         
  116.         mov     ebp,edi                                       
  117.                                                               
  118.         mov     ax,[sinus+si]          
  119.         call    damn
  120.                                                
  121.         mov     ax,[cosinus+si]        
  122.         imul    cx                     
  123.         shl     edx,16                 
  124.         mov     dx,ax                        
  125.         add     edi,edx                
  126.         sar     edi,8                  
  127.         mov     bx,bp                  
  128.         mov     cx,di                  
  129.         ret             
  130. rotate  endp                
  131.                         
  132. mover   proc    near    
  133.         mov     di,ax   
  134.         mov     bp,bx   
  135.         imul    bp,6    
  136.         imul    di,6          
  137.         mov     ax,[trans.x+bp]         
  138.         mov     bx,[trans.y+bp]         
  139.         mov     cx,[trans.x+di]         
  140.         mov     dx,[trans.y+di]         
  141.         push    si                      
  142.         call    line    
  143.         pop     si                      
  144.         ret             
  145. mover   endp            
  146.                                                 
  147. drawobj proc   near                     ; Draw the object
  148.         mov     cx,maxplanes-1
  149.         xor     ah,ah   
  150.         xor     bh,bh   
  151. pllop:  push    cx      
  152.         shl     cx,2                    
  153.         mov     si,cx   
  154.         mov     bl,[planes+si]
  155.         mov     al,[planes+si+1]
  156.         call    mover         
  157.                                                      
  158.         mov     bl,[planes+si+1]
  159.         mov     al,[planes+si+2]
  160.         call    mover         
  161.                                                 
  162.         mov     bl,[planes+si+2]
  163.         mov     al,[planes+si+3]
  164.         call    mover   
  165.                                                 
  166.         mov     bl,[planes+si+3]
  167.         mov     al,[planes+si]
  168.         call    mover           
  169.         pop     cx      
  170.         loop    pllop
  171.         ret                                      
  172. drawobj endp
  173.                           
  174. dorot   macro                           ; Does Rotation, 3D to 2D conv etc
  175.         call    drawobj
  176.         mov     bp,maxpnts*6-6                                            
  177. lΘ:     mov     bx,[ptsxyz.x+bp]                                          
  178.         mov     cx,[ptsxyz.z+bp]                                          
  179.         push    bp                                                        
  180.         call    rotate                                                    
  181.         pop     bp                                                        
  182.         mov     [trans.x+bp],bx                                           
  183.         mov     bx,[ptsxyz.y+bp]                                          
  184.         push    bp                                                        
  185.         call    rotate                                                    
  186.         pop     bp                                                        
  187.         mov     [trans.z+bp],cx                                           
  188.         mov     cx,bx                                                     
  189.         mov     bx,[trans.x+bp]                                           
  190.         push    bp                                                        
  191.         call    rotate                                                    
  192.         pop     bp                                                        
  193.         mov     [trans.x+bp],bx                                           
  194.         mov     [trans.y+bp],cx                                           
  195. ;== 3d 2 2D conversation
  196.         mov     cx,[trans.z+bp]                                           
  197.         add     cx,depth                                                  
  198.         mov     ax,bx   ;[trans.x+bp]                                     
  199.         movsx   dx,ah                                                     
  200.         mov     ah,al                   ; 1 byte less than SHL AX,8
  201.         idiv    cx                               
  202.         add     ax,xpos                          
  203.         mov     [trans.x+bp],ax      
  204.         mov     ax,[trans.y+bp]      
  205.         movsx   dx,ah                
  206.         mov     ah,al                   ; 1 byte!
  207.         idiv    cx                               
  208.         add     ax,ypos   
  209.         mov     [trans.y+bp],ax
  210.                           
  211.         sub     bp,6      
  212.         jns     lΘ        
  213.         mov     color,wirecol
  214.         call    drawobj
  215.         endm              
  216.                                
  217. putpixel macro            
  218.         pusha
  219.         lea     di,[ebx+ebx*4]          ; Very fast and small!
  220.         shl     di,6
  221.         add     di,ax     
  222.         mov     al,color  
  223.         mov     es:[di],al
  224.         popa        
  225.         endm              
  226.  
  227. ;== Draws a line from AX/BX to CX/DX
  228. ;== Original routine by InspirE/TC and Atan/VF (taken from PCUNDERGROUND)
  229. ;== but i've optimised it :))                          
  230. line    proc    near         
  231.         push    bp  
  232.         push    ax  
  233.         push    bx  
  234.         mov     bx,4340h
  235.         sub     cx,ax
  236.         jns     deltax_ok
  237.         neg     cx  
  238.         mov     bl,48h
  239. deltax_ok: mov  bp,sp
  240.         sub     dx,ss:[bp]
  241.         jns     deltay_ok
  242.         neg     dx  
  243.         mov     bh,4bh
  244. deltay_ok: mov  si,dx
  245.         or      si,cx                                                                               
  246.         jne     ok    
  247.         add     sp,6                                                                                
  248.         ret         
  249. ok:     mov     word ptr cs:dist_pos,bx
  250.         cmp     cx,dx
  251.         jge     deltax_gross
  252.         xchg    cx,dx
  253.         mov     bl,90h
  254.         jmp     konstanten
  255. deltax_gross:       
  256.         mov     bh,90h
  257. konstanten:         
  258.         mov     word ptr cs:dist_neg,bx
  259. ;        shl     dx,1
  260.         add     dx,dx        ; is faster than SHL DX,1
  261.         mov     di,dx        
  262.         sub     dx,cx        
  263.         mov     bp,dx        
  264.         mov     si,bp        
  265.         sub     si,cx                                                                               
  266.         xor     ebx,ebx                                                                             
  267.         pop     bx                                                                                  
  268.         pop     ax           
  269. loop_p: putpixel             
  270.         or      bp,bp
  271.         jns     dist_pos
  272. dist_neg: inc   ax   
  273.         inc     bx   
  274.         add     bp,di
  275.         loop    loop_p
  276.         jmp     fertig
  277. dist_pos: inc   ax                                                                                  
  278.         inc     bx                                                                                  
  279.         add     bp,si                                 
  280.         loop    loop_p
  281. fertig: pop     bp                                                                                  
  282.         ret
  283. line    endp                                                                                                 
  284.                           
  285. ufankk: mov     al,13h    
  286.         int     10h       
  287.         mov     di,offset zerodata_start
  288.         mov     cx,offset zerodata_end-zerodata_start
  289.         push    cs        
  290.         pop     es   
  291.         xor     al,al
  292.         rep     stosb         ; Initialeses the Zeroeddata     
  293.         push    cs     
  294.         pop     ds      
  295.                        
  296. ;=== init trig-tables
  297.         xor     si,si  
  298.         xor     di,di  
  299.         mov     cx,64  
  300.         mov     bx,63  
  301. init:   xor     ah,ah  
  302.         mov     al,[sin_init+si]
  303.         mov     [sinus+di],ax
  304.         mov     [cosinus+di+384],ax
  305.         neg     ax                 
  306.         mov     [cosinus+di+128],ax
  307.         xor     ah,ah
  308.         mov     al,[sin_init+bx]
  309.         mov     [cosinus+di],ax
  310.         neg     ax
  311.         mov     [cosinus+di+256],ax
  312.         dec     bx  
  313.         inc     si           
  314.         add     di,2   
  315.         loop    init   
  316.         
  317. ;========== ============
  318. ;   Main Routines 
  319. ;========== ============                
  320.         push    0a000h  
  321.         pop     es      
  322. ll:     mov     color,0
  323.         mov     dx,3dah     ;Vertical Retrace
  324. l1:     in      al,dx                
  325.         test    al,8h     
  326.         jz      l1        
  327.                           
  328.         dorot
  329.         inc     angle.b
  330.                           
  331.         mov     ah,1                         
  332.         int     16h            
  333.         jz      ll             
  334.                           
  335.         mov     ax,0003h
  336.         int     10h                
  337.                                    
  338. ede:    ret                        ; is smaller than MOV AH,4Ch; INT 21h
  339.                                    ; and does the SAME
  340.              
  341. Sin_init db   0,6,13,19,25,31,38,44,50,56
  342.         db   62,69,75,81,87,92,98,104,110,116
  343.         db   121,127,132,137,143,148,153,158,163,168
  344.         db   172,177,182,186,190,194,198,202,206,210
  345.         db   213,217,220,223,226,229,232,235,237,239
  346.         db   241,243,245,247,249,250,251,252,253,254
  347.         db   255,255,255,255   
  348.                                
  349. zerodata_start label               
  350. sinus   dw 64 dup(0)               
  351. cosinus dw 256 dup(0)          
  352. trans   dw maxpnts*4 dup(0)        
  353. bs      dw 0                       
  354. color   db 0
  355. angle  angleun <0>
  356. zerodata_end label                    
  357. code    ends                   
  358.         end     start
  359.              
  360.